import { DataTypes, Model } from "sequelize";
import sequelize from "@db/sequelize";
import { Organization } from "./Organization";

export class Vacancy extends Model {
    declare id: number;
    declare title: string;
    declare description: string;
    declare organizationId?: number;
    declare isRemote: boolean;
    declare isPartTime: boolean;
    declare address: string;
    declare salary?: {
        from: number;
        to: number;
    };
    declare skills: string[];
    declare professionalRole: string;
    declare qualification: string;
}

Vacancy.init(
    {
        id: {
            type: DataTypes.INTEGER,
            allowNull: false,
            primaryKey: true,
            autoIncrement: true,
            unique: true,
        },
        title: {
            type: DataTypes.STRING,
            allowNull: false,
        },
        salary: {
            type: DataTypes.JSONB,
            defaultValue: null,
        },
        address: {
            type: DataTypes.STRING,
        },
        description: { type: DataTypes.STRING },
        isRemote: {
            type: DataTypes.BOOLEAN,
            defaultValue: false,
        },
        isPartTime: {
            type: DataTypes.BOOLEAN,
            defaultValue: false,
        },
        skills: {
            type: DataTypes.JSONB,
            defaultValue: [],
        },
        professionalRole: {
            type: DataTypes.STRING,
            allowNull: true,
        },
        qualification: {
            type: DataTypes.STRING,
        },
    },
    {
        tableName: "vacancies",
        sequelize,
    }
);

Organization.hasMany(Vacancy, {
    foreignKey: "organizationId",
});
